export let ajax = {
    get: function (url, data, callBack) {
        if (typeof data == "function") {
            callBack = data;
        };
        let x = new XMLHttpRequest();
        let str = Object.keys(data).map(item => `${item}=${data[item]}&`).join('').slice(0, -1);
        x.open('get', url + '?' + str);
        x.send();
        x.responseType = 'json';
        x.onreadystatechange = function () {
            if (x.readyState === 4 && x.status === 200) {
                callBack(x.response);
            }
        }
    },
    post: function (url, data, callBack) {
        let x = new XMLHttpRequest();
        x.open('post', url);
        x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
        let str = Object.keys(data).map(item => `${item}=${data[item]}&`).join('').slice(0, -1);
        x.send(str);
        x.responseType = 'json';
        x.onreadystatechange = function () {
            if (x.readyState === 4 && x.status === 200) {
                callBack(x.response);
            }
        }
    }
}